<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-05-05 22:02:56
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-01-10 14:36:49
-->
<template>

  <div ref="right2_container" style="height:95%"></div>

</template>

<script>
import {Pie} from '@antv/g2plot';
import { DEFAULT_COLOR } from '@antv/g2plot/lib/plots/gauge/constants';
import { withDirectives } from 'vue';
export default {
  data (){
    return{
       dataArr:[{ type: '米饭', value: 37 },
  { type: '面食', value: 23 },
  { type: '粥', value: 10 },
  { type: '麻辣烫', value: 5 },
  { type: '火锅', value: 5 },
  { type: '其他', value: 20 },
    ]
     }
  },
created(){
  
},
mounted(){
this.initChart()
},
methods:{
initChart(){
  const pie = new Pie(this.$refs.right2_container,{
 appendPadding: 10,
  data:this.dataArr,
  angleField: 'value',
  colorField: 'type',
  radius: 1,
  innerRadius: 0.6,
  meta: {
    value: {
      formatter: (v) => `¥ ${v}`,
    },
  },
  label: {
    type: 'inner',
    offset: '-50%',
    autoRotate: false,
    style: { textAlign: 'center' },
    formatter: ({ percent }) => `${(percent * 100).toFixed(0)}%`,
  },
  statistic: {
    title: {
      offsetY: -8,
    },
    content: {
      offsetY: -4,
    },
  },
  // 添加 中心统计文本 交互
  interactions: [
    { type: 'element-selected' },
    { type: 'element-active' },
    {
      type: 'pie-statistic-active',
      cfg: {
        start: [
          { trigger: 'element:mouseenter', action: 'pie-statistic:change' },
          { trigger: 'legend-item:mouseenter', action: 'pie-statistic:change' },
        ],
        end: [
          { trigger: 'element:mouseleave', action: 'pie-statistic:reset' },
          { trigger: 'legend-item:mouseleave', action: 'pie-statistic:reset' },
        ],
      },
    },
  ],
});

pie.render();
}
}
}
</script>

<style scoped>

</style>